<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // Es5中的函数参数的默认值写法
        function add(a,b){
            console.log(a+b);
        }

        add(1);//NAN,相当于1+undefined


        // 解决方式
        function add(a,b){
            //短路原则，如果左边返回的是false，就返回右边的值，如果左边的是true,就返回左边的值
            a = a || 0; 
            b = b || 0;
            console.log(a+b);
        }

        add(1);//1


        function fn(a,b){
            a = a || "hello";
            b = b || "wrold";
            console.log(a+" "+b);
        }

        fn(false,false);//hello wrold


        function fn1(a,b){
            if(a === undefined){
                a = "hello";
            }

            b = b === undefined? "world":b;
            console.log(a + " " + b);
        }
        fn1(false,false);//false false


        // Es6中提供了直观的函数参数默认值的写法

        function fn2(a = "hello",b = "world"){
            console.log(a + " " + b);
        }
        fn2();
        fn("hi");
        fn("ok","es6");
        c = "la"
        console.log(typeof c);
    </script>
</body>
</html>